<template>
  <div class="login-container">
    <div class="login">
      <div class="login-title">登 · 录</div>
      <div style="margin-top: 8px">
        <el-tag size="small">账号</el-tag>
        <el-input maxlength="11" v-model="data.account"></el-input>
      </div>
      <div style="margin-top: 8px">
        <el-tag size="small">密码</el-tag>
        <el-input type="password" v-model="data.password"></el-input>
      </div>
      <div style="margin-top: 8px">
        <el-button plain style="width: 100%" type="primary" @click="events.logins">登录</el-button>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ElLoading, ElMessage } from "element-plus";
import { reactive } from "vue";
import { employLogin } from "@/api/order";
import { useRouter } from "vue-router";
import { set_token } from "@/utils/auth";

const data = reactive({
  account: "ccdy",
  password: "123456",
});

const router = useRouter();

const events = {
  async logins() {
    const loading = ElLoading.service({
      lock: true,
      text: "Loading",
      background: "rgba(0, 0, 0, 0.7)",
    });
    const res = await employLogin({
      account: data.account,
      password: data.password,
    });
    if (res.code === 0) {
      set_token(res.data.token.toString());
      ElMessage.success(res.message);
      router.push("/");
      loading.close();
    } else {
      loading.close();
      ElMessage.error(res.message);
    }
  },
};
</script>

<style scoped>
.login-container {
  width: 100vw;
  height: 100vh;
  background: #4594d9;
}

.login {
  width: 350px;
  margin: 0 auto;
  border: 1px solid #eee;
  background-color: #fff;
  padding: 16px;
  border-radius: 4px;
  position: relative;
  top: 100px;
}

.login-title {
  text-align: center;
  border-bottom: 1px solid #eee;
}

body {
  padding: 0;
  margin: 0;
}

.okls {
  width: 100%;
  height: 30px;
}
.activates-acc {
  margin-top: 10px;
}
.and {
  width: 118px;
  background-color: #409eff;
  color: #fff;
  border: #eee 1px solid;
  height: 36px;
  margin-left: 20px;
}
.okhy {
  width: 100%;
  margin-top: 20px;
}
</style>
